package com.future.mayi.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.future.mayi.R;
import com.future.mayi.model.AppraisalGoodsItemModel;
import com.future.mayi.utils.HCUtils;

import java.util.List;

public class AppraisalOrderGoodsItemView extends LinearLayout implements View.OnClickListener {

    private Context mContext;

    private LayoutInflater mInflater;


    private List<AppraisalGoodsItemModel> goods_item;

    public AppraisalOrderGoodsItemView(Context context) {
        super(context);
        init(context);
    }

    public AppraisalOrderGoodsItemView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public AppraisalOrderGoodsItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
        init(context);
    }

    private void init(Context context) {
        mInflater = LayoutInflater.from(context);
        mContext = context;
        setOrientation(VERTICAL);
    }


    public void setGoods_item(List<AppraisalGoodsItemModel> goods_item) {
        if (this.goods_item == goods_item) return;
        this.goods_item = goods_item;
        if (goods_item == null || goods_item.size() == 0) {
            removeAllViews();
            return;
        }
        removeAllViews();
        for (AppraisalGoodsItemModel model : goods_item) {
            View view = mInflater.inflate(R.layout.layout_appraisal_goods_order_item, this, false);
            ImageView ivImg = (ImageView) view.findViewById(R.id.iv_img);
            TextView tvTitle = (TextView) view.findViewById(R.id.tv_title);
            TextView tvNum = (TextView) view.findViewById(R.id.tv_num);
            HCUtils.loadWebImg(mContext, ivImg, model.getCate_img());
            tvTitle.setText(model.getGoods_name());
            tvNum.setText("x".concat(String.valueOf(model.getBuy_num())));
            addView(view);
            view.setTag(model);
//            view.setOnClickListener(this);
        }

    }

    @Override
    public void onClick(View v) {

    }
}
